import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class OutputFile {

	  BufferedWriter out;
	  FileWriter fstream;
	/**
	 * Constructor
	 * 
	 * @param filename_output
	 * output File
	 */
	public OutputFile(String filename_input)
	{
		
		try {
			fstream = new FileWriter(filename_input);
			out = new BufferedWriter(fstream);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}


	/**
	 * The content of the stack is written into the output file
	 * @param st The stack to be printed, st must be not null
	 * @throws : EmptyStackException when st empty
	 */
	public void Stack_to_File(IStack<Object> st) throws EmptyStackException
	{
			if (st.isEmpty()) {
				throw new EmptyStackException("Stack empty!");
			}
			try {
				out.write(st.toString());
				out.flush();
			} catch (IOException e) {
				e.printStackTrace();
			}
		
	}
	
	/**
	 * The content of st is written in the output file
	 * @param : st not empty string
	 */
	public void String_to_File(String st)
	{
			try {
				out.write(st);
				out.write("\n");
				out.flush();
			} catch (IOException e) {
				System.out.println("Error when writing to the output file");
			}
		
	}
	
	/**
	 * Close the output file
	 */
	public void close_File()
	{
		 try {
			out.close();
			fstream.close();
		} catch (IOException e) {
			System.out.println("Error when closing the output file");
		}		
	}
	

}
